﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

// 窗口类
public class SDWindowInfo
{
    public Rect _rect;
    public float Alpha;
    public float UIAlpha;
    public bool Show;
    public float TimeToWait;
    public float Speed;

    public SDWindowInfo(Rect rect, float alpha, bool show, float timeToWait, float speed)
    {
        _rect = rect;
        Alpha = alpha;
        Show = show;
        TimeToWait = timeToWait;
        Speed = speed;
     }
}




public class FrameWork : MonoBehaviour {
    private GUISkin spaceDSkin;
    public Texture2D Image1;
    public Texture2D LoadingAniamtion1;
    int LoadingAnimation1TileX = 23;
    int LoadingAnimation1TileY = 1;
    float LoadingAnimation1FPS = 30.0f;
    Vector2 LoadingAnimation1TexOffset =new  Vector2(0, 0);
    Vector2 LoadingAnimation1TexSize = new Vector2(1 / 23, 1 / 1);
    bool loadAnimationStart = true;
    float LoadingAnimation1Percentage = 0.0f;
    float LA1PUT = 0.100f;
    float LA1NPUT = 0.0f;
    float originalWidth = 1920;
    float originalHeight = 1200;
    Vector3 scale;
    private SDWindowInfo[] SDInfos = new SDWindowInfo[4];

    public bool remeberme = false;
    string textAreaStr = "努力坚持下去，一定会成功！";
    string textFiledStr = "雷潮教育加油！";
    string textFiledStr1 = "点击成功安装";
    string textFiledStr2 = "请输入你的密码";
    string textFiledStr3 = "请输入你的账号";

    Vector2 scollPositon = Vector2.zero;
    string scrollViewText = "Fusce ac justo ornare, tempor purus eu";
    int radioSelected = 0;
    float sliderValue0 = 0.5f;
    float sliderValue1 = 0.5f;

    float newAlpha;
    void Start () {
        // 第一个窗口
        SDInfos[0]._rect = new Rect(0, 0, 484, 711);
        SDInfos[0].Alpha = 0.0f;
        SDInfos[0].UIAlpha = 0.0f;
        SDInfos[0].Show = true;
        SDInfos[0].TimeToWait = 0.0f;
        SDInfos[0].Speed = 2.0f;

        // 第二个窗口
        SDInfos[0]._rect = new Rect(484, 0, 484, 711);
        SDInfos[0].Alpha = 0.0f;
        SDInfos[0].UIAlpha = 0.0f;
        SDInfos[0].Show = true;
        SDInfos[0].TimeToWait = 0.0f;
        SDInfos[0].Speed = 2.0f;

        // 第三个窗口
        SDInfos[0]._rect = new Rect(968, 0, 484, 711);
        SDInfos[0].Alpha = 0.0f;
        SDInfos[0].UIAlpha = 0.0f;
        SDInfos[0].Show = true;
        SDInfos[0].TimeToWait = 0.0f;
        SDInfos[0].Speed = 2.0f;

        // 第四个窗口
        SDInfos[0]._rect = new Rect(1473, 0, 484, 711);
        SDInfos[0].Alpha = 0.0f;
        SDInfos[0].UIAlpha = 0.0f;
        SDInfos[0].Show = true;
        SDInfos[0].TimeToWait = 1.0f;
        SDInfos[0].Speed = 2.0f;
    }

    // Update is called once per frame
    void Update () {
        for (int i = 0; i < SDInfos.Length; i++)
        {
            if (Time.time >= SDInfos[i].TimeToWait)
            {
                float newAlpha;
                if (SDInfos[i].Show)
                {
                    if (SDInfos[i].Alpha < 1.0)
                    {
                        newAlpha = SDInfos[i].Alpha + (Time.deltaTime * SDInfos[i].Speed);
                        SDInfos[i].Alpha = newAlpha;
                        SDInfos[i].UIAlpha = newAlpha;
                    }
                    else
                    {
                        SDInfos[i].Alpha = 1.0f;
                        SDInfos[i].UIAlpha = 1.0f;
                    }
                }
            }
            else
            {

                // 渐变退出
                if (SDInfos[i].Alpha > 0.0)
                {
                    newAlpha = SDInfos[i].Alpha - (Time.deltaTime * SDInfos[i].Speed);
                    SDInfos[i].Alpha = newAlpha;
                    SDInfos[i].UIAlpha = newAlpha - (Time.deltaTime * SDInfos[i].Speed) * 2;
                } else
                {
                    SDInfos[i].Alpha = 0.0f;
                    SDInfos[i].UIAlpha = 0.0f;
                }
            }
        }

        if (loadAnimationStart && LoadingAniamtion1)
        {
            float index = Time.deltaTime * LoadingAnimation1FPS;
            index = index % (LoadingAnimation1TileX * LoadingAnimation1TileY);
            LoadingAnimation1TexSize = new Vector2(1 / LoadingAnimation1TileX, 1 /LoadingAnimation1TileY);

            int totalFrames = LoadingAnimation1TileX * LoadingAnimation1TileY;
            float percentage;
            percentage = (1.0f * index) / (1.0f * totalFrames);
            percentage = percentage * 100;
            if (Time.time >= LA1NPUT)
            {
                LoadingAnimation1Percentage = Mathf.Round(percentage);
                LA1NPUT += LA1PUT;
            }
        }
	}

    private void OnGUI()
    {
        //GUI.skin = spaceDSkin;
        //// Do the windows
        //GUI.color.a = SDInfos[0].Alpha;
        //SDInfos[0]._rect = GUI.Window(0, SDInfos[0]._rect, SDInfos[0], "");

        //GUI.color.a = Windows[1].Alpha;
        //Windows[1].rect = GUI.Window(1, Windows[1].rect, DoWindow1, "");

        //GUI.color.a = Windows[2].Alpha;
        //Windows[2].rect = GUI.Window(2, Windows[2].rect, DoWindow2, "");

        //GUI.color.a = Windows[3].Alpha;
        //Windows[3].rect = GUI.Window(3, Windows[3].rect, DoWindow3, "");

        ////now adjust to the group. (0,0) is the topleft corner of the group.
        //GUI.BeginGroup(Rect(0, 0, 100, 100));
        //// End the group we started above. This is very important to remember!
        //GUI.EndGroup();
    }

    private void DoWindowTitle(int windowID, string text)
    {
        Vector2 bgOffset = new Vector2(36, 15);
        float bgWidth = SDInfos[windowID]._rect.width - (2 * bgOffset.x);
        float bgHeight = 91;
        Rect windowTitleBGRect = new Rect(bgOffset.x, bgOffset.y, bgWidth, bgHeight);

        GUI.Label(windowTitleBGRect, "", "windowTitleBackground");

        Vector2 titleOffset0 = new Vector2(0, 56); 
        Vector2 titleOffset1 = new Vector2(2, 53);
        Vector2 titleOffset2 = new Vector2(-3, 57);
        Vector2 titleOffset3 = new Vector2(1, 55);
        Vector2 titleOffset4 = new Vector2(4, 53);
        Vector2 titleSize = new Vector2(SDInfos[windowID]._rect.width, 29);

        // Draw the title
        GUI.Label(new Rect(titleOffset0.x, titleOffset0.y, titleSize.x, titleSize.y), text, "windowTitle");
        GUI.Label(new  Rect(titleOffset1.x, titleOffset1.y, titleSize.x, titleSize.y), text, "windowTitleShadow");
        GUI.Label(new Rect(titleOffset2.x, titleOffset2.y, titleSize.x, titleSize.y), text, "windowTitleShadow");
        GUI.Label(new Rect(titleOffset3.x, titleOffset3.y, titleSize.x, titleSize.y), text, "windowTitleShadow");
        GUI.Label(new Rect(titleOffset4.x, titleOffset4.y, titleSize.x, titleSize.y), text, "windowTitleShadow");

        Vector2 olOffset = new Vector2(4, 53);
        // Determine the width and height of the title overlay
        float olWidth = SDInfos[windowID]._rect.width - (2 * olOffset.x);
        float olHeight = 55;
        Rect windowTitleOLRect = new Rect(olOffset.x, olOffset.y, olWidth, olHeight);  
        // Lay the title overlay
        GUI.Label(windowTitleOLRect, "", "windowTitleOverlay");
    }

    private void DoWindow0(int windowID)
    {
        //GUI.color.a = SDInfos[windowID].UIAlpha;

        //// Do the window title
        //DoWindowTitle(windowID, "WINDOW TITLE");

        //// Do a text with the first style
        //DoTextStyle1(Rect(79, 134, 332, 71), "Suspendisse potenti. Cras eleifend nisi sit amet molestie pellentesque. Fusce vehicula eros neque, a suscipit tortor tristique id. Nam ullamcorper luctus tempus. Sed posuere volutpat dolor. ");

        //// Do an image
        //if (Image1)
        //    DoImage(Vector2(74, 223), Image1);

        //// Do a separator
        //DoSeparator(Vector2(72, 355));

        //// Do some toggles
        //Windows[3].Show = DoToggle(Vector2(77, 386), Windows[3].Show, "Display the login window?");
        //Windows[1].Show = DoToggle(Vector2(77, 426), Windows[1].Show, "Display the second window?");
        //Windows[2].Show = DoToggle(Vector2(77, 466), Windows[2].Show, "Display the thrid window?");

        //// Do a fliped separator
        //DoSeparator(Vector2(72, 511));

        //// Do a text with the second style
        //DoTextStyle2(Rect(72, 550, 339, 90), "Suspendisse potenti. Cras eleifend nisi sit amet molestie pellentesque. Fusce vehicula eros neque, a suscipit tortor tristique id. Nam ullamcorper luctus tempus. Sed posuere volutpat dolor. ");

        //// Make the windows be draggable.
        //GUI.DragWindow(Rect(0, 0, 10000, 10000));
    }

}


